﻿using UnityEngine;

namespace JH
{
    public static class CalcGameObjectDepthRealization
    {
        /// <summary>
        /// 计算物体的深度
        /// </summary>
        public static float CalcDepthEm(this UnityEngine.GameObject go, Camera renderCamera)
        {
            if (go == null)
                throw new System.ArgumentNullException(nameof(go),
                    "必须传入一个物体，才能计算物体的深度");

            if (renderCamera == null)
                throw new System.ArgumentNullException(nameof(renderCamera),
                    "必须传入一个相机，才能计算物体的深度");

            return go.CalcScreenPositionEm(renderCamera).z;
        }
    }
}